package com.siruier.boss.ui.activity.commom

import android.content.ComponentName
import android.content.Intent
import android.view.View
import com.siruier.boss.R
import com.siruier.boss.api.SysConfig
import com.siruier.boss.databinding.ActivityContactCustomerServiceBinding
import com.siruier.boss.ui.base.BaseActivity
import com.siruier.boss.ui.ext.clipboard
import com.siruier.boss.ui.ext.toastMessageLong
import com.siruier.boss.ui.helper.AppConfigHelper.loadConfig

class ContactCustomerServiceActivity : BaseActivity<ActivityContactCustomerServiceBinding>() {
    private var mSysConfig: SysConfig? = null

    override fun initView() {
        bindViewClick(vb.tvCustomerServiceNote, vb.buttonCopyWxNumber, vb.buttonOpenWx)
    }

    override fun initData() {
        loadConfig{
            mSysConfig = it
            vb.tvCustomerServiceNote.text = getString(R.string.text_customer_service_note,it.appCustomerServicePhone)
            vb.tvCustomerServiceWxNote.text = getString(R.string.text_customer_service_wx_note,it.appCustomerServiceWx)
        }
    }
    override fun onClick(v: View?) {
        when (v) {
            vb.buttonCopyWxNumber -> {
                mSysConfig?.appCustomerServiceWx.clipboard()
            }
            vb.buttonOpenWx -> openWx()
        }
    }

    private fun openWx() {
        try {
            val intent = Intent()
            val cmp = ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI")
            intent.action = Intent.ACTION_MAIN
            intent.addCategory(Intent.CATEGORY_LAUNCHER)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            intent.component = cmp
            startActivity(intent)
        } catch (e: Exception) {
            "无法跳转到微信，请检查您是否安装了微信！".toastMessageLong()
        }
    }
}